package work01;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class work7maze {
    public static void main(String[] args) {
        int [][] arr = new int [5][5];
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> WS = new ArrayList<Integer>();
        ArrayList<Integer> AD = new ArrayList<Integer>();
        Random rand = new Random();
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                arr[i][j] = rand.nextInt(2);
            }
        }
        arr[0][0] = 0;
        arr[4][4] = 0;
        System.out.println("输入wasd/");

        while(WS.size()-1!=arr.length && AD.size()-1!=arr.length) {
            for (int i = 0; i < arr.length; i++) {
                for (int j = 0; j < arr.length; j++) {
                    if(WS.size()==i && AD.size()==j) {
                        System.out.print("*" + " ");
                    }else{
                        System.out.print(arr[i][j] + " ");
                    }
                }
                System.out.println(" ");
            }
            String s = sc.nextLine();

            switch (s) {
                case "w": W(WS,AD,arr); break;
                case "s": S(WS,AD,arr); break;
                case "a": A(WS,AD,arr); break;
                case "d": D(WS,AD,arr); break;
            }
        }
        System.out.println("你走出了迷宫！");

    }
    public static void W(ArrayList<Integer> WS,ArrayList<Integer> AD,int[][] arr) {
        if(arr[WS.size()-1][AD.size()]==0) {
            WS.remove(WS.size()-1);
        } else if (arr[WS.size()-1][AD.size()]==1) {
            System.out.println("不能通过");
        }
    }
    public static void S(ArrayList<Integer> WS,ArrayList<Integer> AD,int[][] arr) {
        if(arr[WS.size()+1][AD.size()]==0) {
            WS.add(0);
        } else if (arr[WS.size()+1][AD.size()] == 1) {
            System.out.println("不能通过");
        }

    }
    public static void A(ArrayList<Integer> WS,ArrayList<Integer> AD,int[][] arr) {
        if(arr[WS.size()][AD.size()-1]==0) {
            AD.remove(AD.size()-1);
        } else if (arr[WS.size()][AD.size()-1] == 1) {
            System.out.println("不能通过");
        }

    }
    public static void D(ArrayList<Integer> WS,ArrayList<Integer> AD,int[][] arr) {
        if(arr[WS.size()][AD.size()+1]==0) {
            AD.add(0);
        } else if (arr[WS.size()][AD.size()+1] == 1) {
            System.out.println("不能通过");
        }
    }
}
